//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：EditorInspector
// *描述：用于绘制UIDisplay的Editor脚本
// *?2021 MYJL . All rights reserved.
//* ======================================================================
using HDMCode.FrameEditor;
using HDMCode.UIFrame;
using UnityEditor;
using UnityEngine;

namespace HDMCode.UIFrameEditor
{
    [CustomEditor(typeof(UIDisplay))]
    public class EditorInspector : Editor
    {
        private UIDisplay m_Script;
        
        /// <summary>
        /// 通过绘制脚本
        /// </summary>
        private EditorInspectorSuccess m_Success;
        
        /// <summary>
        /// 异常绘制脚本
        /// </summary>
        private EditorInspectorError m_Error;

        /// <summary>
        /// Inspector初始化
        /// </summary>
        public virtual void OnEnable()
        {
            HDMEditorStyle.InitStyle();
            m_Script = (UIDisplay)target;
            m_Success = new (m_Script);
            m_Error = new (m_Script);
            m_Success.CreateReorderableList(serializedObject, serializedObject.FindProperty("components"), "组件", "UI元素", "UI组件");
        }
        
        /// <summary>
        /// Inspector绘制
        /// </summary>
        public override void OnInspectorGUI()
        {
            EditorGUILayout.CreatTile();
            if (m_Error.CheckAssets())
            {
                DrawField();
                serializedObject.Update();
                UnityEditor.EditorGUILayout.Space(EditorGUIUtility.singleLineHeight / 4);
                m_Success.ComponentElementList.DoLayoutList();
                UnityEditor.EditorGUILayout.Space(EditorGUIUtility.singleLineHeight / 2);
                serializedObject.ApplyModifiedProperties();
                m_Success.DrawRelevance();
                HDMEditorHelper.DrawXLine(5);
                if (GUI.changed)
                {
                    EditorUtility.SetDirty(target);
                }
            }
            else
            {
                m_Error.DrawAssetsName();
                m_Error.DrawAssetsDescription();
                m_Error.DrawError();
            }
        }
        
        /// <summary>
        /// 绘制Inspector面板显示选项
        /// </summary>
        public void DrawField()
        {
            m_Success.DrawAssetsName();
            m_Success.DrawAssetsDescription();
#pragma warning disable CS0618
            m_Success.DrawSupportXlua();
#pragma warning restore CS0618
            m_Success.DrawWrapper();
            m_Success.DrawShow();
            m_Success.DrawPierce();
            m_Success.DrawBackGround();
            m_Success.DrawSetBackGroundColor();
            m_Success.DrawSetAnimation();
            m_Success.DrawSetAudio();
            HDMEditorHelper.DrawXLine(5);
        }
    }
}




